import { postFileUpload } from "@/api/infra/file";

export function beforeUpload(file) {
  const isImg = file.type.indexOf("image/") !== -1;
  const isLt2M = file.size / 1024 / 1024 < 2;

  if (!isImg) {
    this.$message.error("上传电子签章不是图片!");
  }
  if (!isLt2M) {
    this.$message.error("上传电子签章图片大小不能超过 2MB!");
  }
  return isImg && isLt2M;
}

export function submitUpload(option) {
  console.log("submit upload", option);
  let formData = new FormData();
  formData.append(
    option.filename || "file",
    new Blob([option.file], { type: option.file.type }),
    option.file.name
  );
  return postFileUpload(formData);
}
